package com.cskaoyan.order.controller;

import com.cskaoyan.mall.commons.result.ResponseData;
import com.cskaoyan.mall.commons.result.ResponseUtil;
import com.cskaoyan.mall.order.constant.OrderRetCode;
import com.cskaoyan.order.dto.OrderDetailNewResponse;
import com.cskaoyan.order.dto.OrderDetailRequest;
import com.cskaoyan.order.service.OrderQueryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/shopping")
public class OrderController {

    @Autowired
    OrderQueryService orderQueryService;


    @GetMapping("/order/{id}")
    public ResponseData OrderDetailCarts(@PathVariable("id") String id){
//        String userInfo = (String) r.getHeader("user_info");
//        JSONObject object = JSON.parseObject(userInfo);
//        Long uid = Long.parseLong(object.get("uid").toString());
        OrderDetailRequest request = new OrderDetailRequest();
        request.setOrderId(id);

        OrderDetailNewResponse response = orderQueryService.orderDetail(request);
        if(OrderRetCode.SUCCESS.getCode().equals(response.getCode())){
            return new ResponseUtil().setData(response);
        }
        return new ResponseUtil().setErrorMsg(response.getMsg());
    }

}
